package com.kawaiior.asoulworld.item.weapon;

import com.kawaiior.asoulworld.item.ItemASWeapon;
import com.kawaiior.asoulworld.util.EntityUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class ItemAvaDrill extends ItemASWeapon {


    public ItemAvaDrill(String name, ToolMaterial material) {
        super(name, material);
        useable = true;
        base_cd = 20f;
        base_power = 6f;
        attackDamage = 14f;
    }

    @Override
    public boolean canHarvestBlock(IBlockState blockIn)
    {
        return true;
    }

    @Override
    public float getDestroySpeed(ItemStack stack, IBlockState state)
    {
        Block block = state.getBlock();
        if (block == Blocks.OBSIDIAN)
        {
            return 100.0F;
        }
        if (block == Blocks.DIRT)
        {
            return 3F;
        }
        if (block == Blocks.SAND)
        {
            return 3F;
        }
        return 20F;
    }

    @Override
    public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
    {
        if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
        {
            stack.damageItem(1, entityLiving);
        }

        return true;
    }

    @Override
    public int getMaxDamage(ItemStack stack) {
        return 3072;
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 10;
    }

    @Override
    public void onCreatureStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
        if (!worldIn.isRemote) {
            EntityUtil.ApplyBuff(entityLiving, MobEffects.RESISTANCE, 4, 1);
            entityLiving.world.createExplosion(entityLiving, entityLiving.posX, entityLiving.posY, entityLiving.posZ, base_power, false);
            stack.damageItem(64, entityLiving);
        }
    }

}
